package org.jsbd.boss.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.http.util.EncodingUtils;

public class EncUtil {
    private static final char[] HEXADECIMAL = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 };

    private static String encode(byte[] paramArrayOfByte) {
        int j = paramArrayOfByte.length;
        char[] arrayOfChar = new char[j * 2];
        int i = 0;
        while (i < j) {
            int k = paramArrayOfByte[i];
            int m = paramArrayOfByte[i];
            arrayOfChar[(i * 2)] = HEXADECIMAL[((m & 0xF0) >> 4)];
            arrayOfChar[(i * 2 + 1)] = HEXADECIMAL[(k & 0xF)];
            i += 1;
        }
        return new String(arrayOfChar);
    }

    public static boolean isEmpty(String paramString) {
        return (paramString == null) || (paramString.trim().length() == 0);
    }

    public static boolean isRightEmail(String paramString) {
        if (isEmpty(paramString)) {
            return false;
        }
        return paramString.matches("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
    }

    public static boolean isRightPassId(String paramString) {
        if (isEmpty(paramString)) {
            return false;
        }
        return paramString.matches("^[1-9]\\d{8,14}$");
    }

    public static boolean isRightPhone(String paramString) {
        if (isEmpty(paramString)) {
            return false;
        }
        return paramString.matches("1\\d{10}");
    }

    public static boolean isRightTempSmsPwd(String paramString) {
        if (isEmpty(paramString)) {
        }
        while (!paramString.matches("\\d{6}")) {
            return false;
        }
        return true;
    }

    public static String toMd5(String paramString) {
        try {
            paramString = encode(MessageDigest.getInstance("MD5").digest(EncodingUtils.getAsciiBytes(paramString)));
            return paramString;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String toMd5(byte[] paramArrayOfByte) {
        try {
            return encode(MessageDigest.getInstance("MD5").digest(paramArrayOfByte));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
